﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace YFIN.Admin.Helper
{
    public class Counter
    {
        private int currentCount = 0;
        private DispatcherTimer timer;

        public int Increment
        {
            get;
            set;
        }

        public TimeSpan Timeout
        {
            get;
            set;
        }

        public int Count
        {
            get
            {
                if (this.timer == null)
                {
                    this.timer = new DispatcherTimer();
                    this.timer.Interval = this.Timeout;
                    this.timer.Tick += (o, e) =>
                        {
                            this.Reset();
                        };
                    this.timer.Start();
                }
                this.currentCount += this.Increment;
                return this.currentCount;
            }
        }

        public void Reset()
        {
            this.currentCount = 0;
            if (this.timer != null)
            {
                this.timer.Stop();
                this.timer = null;
            }
        }

        public Counter()
        {
            // Insert code required on object creation below this point.
        }
    }
}
